package com.td.core.obj;

import com.td.core.communication.Sendable;
import com.td.core.communication.obj.GameStateInfo;

public class TDGame implements Sendable<TDGame> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public static final int MAX_PLAYERS = 8;
	
	private Player[] players;
	
	private GameStateInfo gameStateInfo;
	
	public TDGame(int size) {
		players = new Player[size];
		for(int i = 0; i < size; i++) {
			players[i] = new Player();
		}
		
		this.gameStateInfo = new GameStateInfo();
	}
	
	public TDGame(TDGame gm) {
		players = new Player[gm.players.length];
		for(int i = 0; i < players.length; i++) {
			players[i] = new Player(gm.players[i]);
		}
		
		this.gameStateInfo = gm.getStateInfo().getCopy();
	}
	
	public synchronized Player[] getPlayers() {
		return players;
	}

	@Override
	public synchronized void copyTo(TDGame obj) {
		synchronized (obj) {
			for(int i = 0; i < obj.players.length; i++) {
				this.players[i].copyTo(obj.players[i]);
			}
			this.gameStateInfo.copyTo(obj.gameStateInfo);
		}
	}

	@Override
	public TDGame getCopy() {
		return new TDGame(this);
	}

	public synchronized GameStateInfo getStateInfo() {
		return gameStateInfo;
	}

	public synchronized void setStateInfo(GameStateInfo gameStateInfo) {
		this.gameStateInfo = gameStateInfo;
	}
}
